<?php
class Search_model extends Model {

    function Search_model()
    {
        // Call the Model constructor
        parent::Model();
    }
	
	function tours($searchParams)
	{
		$this->db->select('tours.*, ' . $this->db->dbprefix . 'tourtypes.tour_name, ' . $this->db->dbprefix . 'tourtypes.tour_code');
		
		// Tour ID
		if ($searchParams['tourId'])
		{
			$this->db->where('tours.id', $searchParams['tourId']);
		} else
		{
			if ($searchParams['tourtype'] > 0)
			{
				$this->db->where('tourtypes.id', $searchParams['tourtype']);
			}
			
			if (isset($searchParams['active_tours']))
			{
				$this->db->where('active', 1);
			}
			
			if ($searchParams['departure_date'])
			{
				$this->db->where('departure', date_for_db($searchParams['departure_date']));
			} else
			{
				if ($searchParams['start_date'])
				{
					$this->db->where('departure >=', date_for_db($searchParams['start_date']));
				}
				
				if ($searchParams['end_date'])
				{
					$this->db->where('departure <=', date_for_db($searchParams['end_date']));
				}
			}
		}
		
		$this->db->where('tourtypes.id = ' . $this->db->dbprefix . 'tours.tourtype_id');
		$this->db->order_by('departure');
		$query = $this->db->get('tours, ' . $this->db->dbprefix . 'tourtypes');
		
		$tours = $query->result_array();
		
		return $tours;	
	}
	

}
?>